import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-09-24
 * Time: 19:37
 */
class Student{
    private static Student student = null;
    private int a = 0;
    private Student(){

    }

    public static Student getStudent(){
        if(student == null){
            student = new Student();
        }
        return student;
    }

}

public class Test {
    public static void main(String[] args) {
        ReentrantLock reentrantLock = new ReentrantLock();
        reentrantLock.lock();//加锁,加锁不超过，一直阻塞等待
        reentrantLock.unlock();//解锁
        reentrantLock.tryLock();//加锁，加锁不成功，直接返回false或者设置等待时间。
    }
//    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        Callable<Integer> callable = new Callable<Integer>() {
//            @Override
//            public Integer call() throws Exception {
//                int sum = 0;
//                for(int i = 0; i <= 1000; i++){
//                    sum += i;
//                }
//                return sum;
//            }
//        };
//        FutureTask<Integer> task = new FutureTask<>(callable);
//        Thread t1 = new Thread(task);
//        t1.start();
//        System.out.println(task.get());
//    }
//    public static AtomicInteger atomicInteger = new AtomicInteger(0);
//    public static void main(String[] args) throws InterruptedException {
//        Thread thread = new Thread(() -> {
//            for (int i = 0; i < 10000; i++) {
//                atomicInteger.getAndIncrement();//相当于count++
////                atomicInteger.incrementAndGet();//相当于++count
////                atomicInteger.decrementAndGet();//相当于--count
////                atomicInteger.getAndDecrement();//相当于count--；
//            }
//        });
//
//        Thread thread1 = new Thread(() -> {
//            for (int i = 0; i < 10000; i++) {
//                atomicInteger.getAndIncrement();
//            }
//        });
//
//        thread.start();
//        thread1.start();
//        thread.join();
//        thread1.join();
//        System.out.println(atomicInteger.get());
//    }
}
